<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="de.nava.informa.core.ChannelIF"%>
<%@page import="de.nava.informa.parsers.FeedParser"%>
<%@page import="de.nava.informa.impl.basic.ChannelBuilder"%>
<%@page import="java.util.Iterator"%>
<%@page import="de.nava.informa.core.ItemIF"%>
<%@page import="java.util.Calendar"%>
<%@page import="net.groupme.model.cache.CachedObjectType"%>
<%@page import="net.groupme.model.ObjectFactory"%>
<%@page import="net.groupme.controller.model.HtmlFormattedElement"%>
<%@page import="net.groupme.model.cache.CachedObject"%>
<%@page import="net.groupme.stats.StatManager"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<!-- meta tags, link to css:  -->
	<%@ include file="./jsp-includes/metaheader.jsp" %>
	
	<!--  Ajax-Includes -->
    <script type='text/javascript' src='/GroupMe/dwr/interface/DWRUserManager.js'></script>
    <script type='text/javascript' src='/GroupMe/dwr/engine.js'></script>
    <script type='text/javascript' src='/GroupMe/dwr/util.js'></script>

	<title>Welcome to GroupMe! ...where Semantic Web meets Web 2.0</title>
</head>
<body>
	<!-- title image, logo:  -->
	<div id="header">
		<%@ include file="./jsp-includes/titleheader.jsp" %>
	</div>
	
	<!-- Menu: -->
	<div id="menu">
		<%@ include file="./jsp-includes/menu.jsp" %>
	</div>
	<!-- content and sidebar -->
	<div id="main">

		<!-- Sidebar -->
		<div id="sidebar">
			<c:choose>
			<c:when test="${userManager.loggedIn}">
			 	<p>logged in as <c:out value="${userManager.user.userName}"/></p>
		     	<a href="<%= VIEW_VOCABULARY.ACTION_LOGOUT %>" title="logout and go to welcome page">logout</a>
			<br/><br/>
			</c:when>
			<c:otherwise>
			<p><strong>Login:</strong></p>
			<form name="login" action="<%= VIEW_VOCABULARY.ACTION_LOGIN %>" method="post">
				username: 
				<input type="text" name="<%= VIEW_VOCABULARY.PARAMETER_USERNAME %>" value="<c:out value='${username}'/>"/>
				password: <input type="password" name="<%= VIEW_VOCABULARY.PARAMETER_PASSWORD %>"/> 

				<br/><input type="checkbox" name="<%= VIEW_VOCABULARY.PARAMETER_KEEP_PERMANENT_LOGGED_IN %>"/>
				<i>remember me</i>
				<br/><input type="submit" value="login"/> 

			</form>
			<br/>
				<a href="<%= request.getContextPath() + "/" + VIEW_VOCABULARY.ACTION_REGISTRATION %>" title="Create a GroupMe! account">Register</a>
				<br/><br/>
			</c:otherwise>
			</c:choose>
			<p>
			<strong>Quick start:</strong><br/>
			- news: <a href="http://groupme.org/blog/" title="GroupMe! project Blog [new features, events, etc.]">blog</a><br/>
			- video: <a href="http://groupme.org/videos/grouping/" title="Create your first GroupMe! group (47 MB)">[high]</a> <a href="http://groupme.org/videos/grouping-800x600/" title="Create your first GroupMe! group (31 MB)">[low]</a><br/>
			- register: <a href="<%= request.getContextPath() + "/" + VIEW_VOCABULARY.ACTION_REGISTRATION %>" title="Create a GroupMe! account">here</a><br/>
			- api: <a href="<%= request.getContextPath() + "/api/" %>" title="documentation">doc</a><br/>
			</p>
			
			<!-- NEWS -->
			<% final String blogUrl = "http://groupme.org/blog/?feed=rdf";
			ChannelIF channel = null;
			try{
				channel = FeedParser.parse(new ChannelBuilder(), blogUrl);
			}catch(Exception e){%>
				channel = null;
			<% } %>
			<% if(channel != null){%>
				<br/><strong>News:</strong><br/>
				<%  Iterator itemIterator = channel.getItems().iterator();
					int numberOfDisplayedNews = 1;
					while(itemIterator.hasNext() && numberOfDisplayedNews <= 3){
						ItemIF item = (ItemIF)itemIterator.next(); 
						//date:
						Calendar date = Calendar.getInstance();
						date.setTime(item.getDate());
						//description:
						String description = item.getDescription();
						if(description != null){
							//while(description.contains("<") && description.contains(">")){
							//	description = description.substring(0, description.indexOf("<")) +
							//		description.substring(description.indexOf(">") + 1);
							//} TODO: das sollte man wieder so machen, dass die description angezeigt wird, allerdings gab es einen Fehler mit 
							// dem folgenden Blogeintrag: http://groupme.org/blog/?p=9
							if(description.contains("<")){
								description = item.getTitle() + "...";
							}else{
								description = item.getDescription();
							}
						}
						if(description != null && description.length() > 150){
							description = description.substring(0, 150);
						}
						%>
						<div class="newsitem" style="margin-bottom: 1.0em">
						[<%= date.get(Calendar.YEAR) + "-" + (date.get(Calendar.MONTH) + 1) + "-" + date.get(Calendar.DATE) %>] <br/>
						<a href="<%= item.getLink() %>" title="<%= description %>"><%= item.getTitle() %></a>
						</div>
					<% numberOfDisplayedNews++;
					} %>
			<%} %>
			<% StatManager sm = new StatManager(); %>
			<div>		
			<br/><strong>Stats:</strong><br/>		
				- Users: <%= sm.getUsers() %> <br/>
				- Groups: <%= sm.getGroups() %> <br/>
				- Resources: <%= sm.getResources() %> <br/>
				- Tags: <%= sm.getTags() %> <br/>
			</div>
		</div>


		<!-- Content: -->
		<div id="content">
			<h1>Welcome to GroupMe!</h1>
			<p>We are proud to introduce you the beta version of the <i>GroupMe!</i> system. It combines 
			<a href="http://www.w3.org/2001/sw/" title="Semantic Web application">Semantic Web</a> technologies and 
			<a href="http://www.oreillynet.com/lpt/a/6228" title="What Is Web 2.0 - Design Patterns and Business Models for the Next Generation of Software">Web 2.0</a> 
			technologies, and demonstrates a new kind of social tagging system. <a href="<%= request.getContextPath() + "/" + VIEW_VOCABULARY.ACTION_ABOUT %>" title="About GroupMe! - background">Read more...</a></p>
			<table>
				<tr>
					<td width="30%">
					<p><strong>GroupMe! features:</strong></p>
					<ul>
						<li>create groups of multimedia web resources via <i>drag & drop</i></li>
						<li>style groups the way you like it (like mind maps)</li>
						<li>tag resources and groups</li>
						<li>search for groups and resources of other users</li>
						<li>write own applications by using the GroupMe! API</li>
						<li>...</li>
					</ul>
					</td>
					<td>
						<img src="./images/groupme-approach.png" width="600px"/>
					</td>
				</tr>
			</table>
			<p style="text-align: center;"><strong>Explore most frequent tags...</strong></p>
			<div id="tagcloud">
				<%	CachedObject cloud = ObjectFactory.getCachedObject(CachedObjectType.TAG_CLOUD_WHOLE, null, null);
					if(cloud != null){ %>
						<%= ((HtmlFormattedElement)cloud.getChachedObject()).getHtml() %>
				<%} %>
			</div>
			<br/>
			<p><strong>How to start?</strong></p>
			<ul>
				<li>Have a look at the video to get an impression: <a href="http://groupme.org/videos/grouping/" title="Create your first GroupMe! group">[high quality]</a> <a href="http://groupme.org/videos/grouping-800x600/" title="Create your first GroupMe! group">[medium quality]</a></li>
				<li>You want to build own groups? <a href="<%= request.getContextPath() + "/" + VIEW_VOCABULARY.ACTION_REGISTRATION %>" title="Create a GroupMe! account">Register here.</a></li> 
				<li>Just interested in groups of other users? <a href="<%= request.getContextPath() + "/" + VIEW_VOCABULARY.ACTION_BROWSE_GROUPS %>" title="GroupMe! Browse Groups">Start browsing</a>, go to <a href="<%= request.getContextPath() + "/" + VIEW_VOCABULARY.ACTION_SEARCH %>" title="GroupMe! Search">search</a> or just click on a tag of the tag cloud above. </li>
				<li>You want to benefit from the RDF that is produced by GroupMe! in your own applications? Use the <a href="<%= request.getContextPath() + "/api/" %>" title="GroupMe! API">GroupMe! API</a></li>
			</ul>
			<p><strong>Enjoy GroupMe!</strong><br/><br/>
			<i>Your GroupMe! Team</i></p>
			<br/>
			<span style="font-size:0.8em">GroupMe! has been tested on Firefox/IE and partly on Safari. Please inform us if you have any problems.</span>
		</div>
	</div>
	
	<div id="footer">
		<%@ include file="./jsp-includes/footer.jsp" %>
	</div>
</body>
</html>